$(document).ready(function () {

	//jQuery UI Buttons
	var buttons = $('button, a.button, :submit:visible, :button').button();

	$(buttons).filter('[data-icon]').each(function () {
		$(this).button('option', 'icons', {primary: 'ui-icon-' + $(this).data('icon') });

		if ($(this).data('no-text')) {
			$(this).button('option', 'text', false);
		}
	});

	$(buttons).filter('.disabled').button('option', 'disabled', true).click(function () { return false; });
	$(buttons).filter('.secondary').removeClass('.secondary').addClass('ui-priority-secondary');


	//Colorbox for iframes
	$('a.iframe').each(function () {
		var url = $(this).attr('href');

		if (url.match(/\?/)) {
			url += '&phpcan_exit_mode=iframe';
		} else {
			url += '?phpcan_exit_mode=iframe';
		}

		$(this).colorbox({
			href: url,
			iframe: true,
			width: '90%',
			height: '90%',
			opacity: 0.2,
			overlayClose: false,
			onOpen: function() {
				$('body').css('overflow', 'hidden');
			},
			onClosed: function() {
				$('body').css('overflow', 'auto');
			}
		});
	});

	//Colorbox for images
	$('a[href$=".jpg"],a[href$=".jpeg"],a[href$=".gif"],a[href$=".png"]').colorbox({
		opacity: 0.2
	});

	//Float header
	$('table.list').floatHeader({
		fadeOut: 1,
		fadeIn: 1
	});

	//Message
	$('#message').click(function () {
		$(this).slideUp('fast');
	});

	$('#message.success').delay(4000).slideUp('slow');

	//Html5 Forms
	$.ansForms();

	//Input type=text class="datetime"
	$('input[type=text].datetime').each(function () {
		$(this).datepicker({
			dateFormat: 'dd-mm-yy',
			onSelect: function(text) {
				var date = new Date();

				if (text.indexOf(':') == -1) {
					var hour = date.getHours();
					var minute = date.getMinutes();
					var second = date.getSeconds();
					var current_time = ((hour < 10)?('0'+hour):hour)+':'+((minute < 10)?('0'+minute):minute)+':'+((second < 10)?('0'+second):second);

					$(this).val(text + ' ' + current_time);
				}
			}
		});
	});
	
	//Input type=text class="date"
	$('input[type=text].date').each(function () {
		$(this).datepicker({
			dateFormat: 'dd-mm-yy'
		});
	});
});